home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / what's new / sample code / human interface toolbox / packagetool / packageutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-22  |  2.7 KB  |  76 lines

  1. /*
  2.     file PackageUtils.c
  3.     
  4.     Description:
  5.     This file contains the package utility function IdentifyPackage that
  6.     package savy applications can use for identifying document packages.
  7.     
  8.     PackageTool is an application illustrating how to create application
  9.     packages in Mac OS 9.  It provides a simple interface for converting
  10.     correctly formatted folders into packages and vice versa.
  11.  
  12.     by John Montbriand, 1999.
  13.  
  14.     Copyright: © 1999 by Apple Computer, Inc.
  15.     all rights reserved.
  16.     
  17.     Disclaimer:
  18.     You may incorporate this sample code into your applications without
  19.     restriction, though the sample code has been provided "AS IS" and the
  20.     responsibility for its operation is 100% yours.  However, what you are
  21.     not permitted to do is to redistribute the source as "DSC Sample Code"
  22.     after having made changes. If you're going to re-distribute the source,
  23.     we require that you make it clear in the source that the code was
  24.     descended from Apple Sample Code, but that you've made changes.
  25.     
  26.     Change History (most recent first):
  27.     10/19/99 created by John Montbriand
  28. */
  29.  
  30. #include "PackageUtils.h"
  31. #include <Aliases.h>
  32.  
  33. /* IdentifyPackage returns true if the file system object refered to
  34.     by *target refers to a package.  If it is a package, then 
  35.     *mainPackageFile is set to refer to the package's main file. */
  36. Boolean IdentifyPackage(FSSpec *target, FSSpec *mainPackageFile) {
  37.     CInfoPBRec cat;
  38.     OSErr err;
  39.     long packageFolderDirID;
  40.     Str255 name;
  41.     FSSpec aliasFile;
  42.     Boolean targetIsFolder, wasAliased;
  43.         /* check the target's flags */
  44.     cat.dirInfo.ioNamePtr = target->name;
  45.     cat.dirInfo.ioVRefNum = target->vRefNum;
  46.     cat.dirInfo.ioFDirIndex = 0;
  47.     cat.dirInfo.ioDrDirID = target->parID;
  48.     err = PBGetCatInfoSync(&cat);
  49.     if (err != noErr) return false;
  50.     if (((cat.dirInfo.ioFlAttrib & 16) != 0) && ((cat.dirInfo.ioDrUsrWds.frFlags & kHasBundle) != 0)) {
  51.             /* search for a top level alias file */
  52.         packageFolderDirID = cat.dirInfo.ioDrDirID;
  53.         cat.dirInfo.ioNamePtr = name;
  54.         cat.dirInfo.ioVRefNum = target->vRefNum;
  55.         cat.dirInfo.ioFDirIndex = 1;
  56.         cat.dirInfo.ioDrDirID = packageFolderDirID;
  57.             /* find the first alias file in the directory */
  58.         while (PBGetCatInfoSync(&cat) == noErr) {
  59.             if (((cat.dirInfo.ioFlAttrib & 16) == 0) && ((cat.dirInfo.ioDrUsrWds.frFlags & kIsAlias) != 0)) {
  60.                 err = FSMakeFSSpec(target->vRefNum, packageFolderDirID, name, &aliasFile);
  61.                 if (err != noErr) return false;
  62.                 err = ResolveAliasFile(&aliasFile, false, &targetIsFolder, &wasAliased);
  63.                 if (err != noErr) return false;
  64.                 if (mainPackageFile != NULL)
  65.                     *mainPackageFile = aliasFile;
  66.                 return true;
  67.             }
  68.             cat.dirInfo.ioFDirIndex++;
  69.             cat.dirInfo.ioDrDirID = packageFolderDirID;
  70.         }
  71.     }
  72.         /* no matching files found */
  73.     return false;
  74. }
  75.  
  76.